package com.zhangxujie.litewords.db;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.room.Room;
import androidx.sqlite.db.SimpleSQLiteQuery;

import com.zhangxujie.litewords.R;
import com.zhangxujie.litewords.api.Const;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import static android.content.Context.MODE_PRIVATE;

public class DBUtil {

    private static volatile AppDatabase db;
    private static SharedPreferences mSpf;
    public static final String DATABASE_FILENAME = "words.db";
    public static final String PACKAGE_NAME = "com.zhangxujie.litewords";
    public static final String DATABASE_PATH = "/data/data/" + PACKAGE_NAME + "/databases";


    private DBUtil() {


    }

    public static AppDatabase getDb(final Context ctx) {
        if (db == null) {
            synchronized (AppDatabase.class) {
                if (db == null) {
                    db = Room.databaseBuilder(ctx,
                            AppDatabase.class, "words.db")
                            .createFromAsset("words.db")
                            .build();

                }
            }
        }
        return db;
    }

}
